<template>
  <div>
       <page-header title="学生信息批量注册" content="large size sutdent register" />
       <page-main title="学生批量注册时，只需填入学号，密码默认为学号后6位">
            <el-row>
                <el-col :span="10">
                    <file-upload :files="files" action="http://localhost:8000/public/upload2" name="file" :data="{'token':'TKD628431923530324'}" @handlesuccess3="handlesuccess3" :ext="['xls']" succuss="handlesuccess3"/>
                </el-col>
                <el-col :span="4"><p></p></el-col>
                <el-col :span="10" >
                    <el-row>
                        <el-card style="text-align: center;">
                            <el-row>ps:请按照模板数据添加</el-row>
                            <br>
                            <el-row><el-button icon="el-icon-circle-plus-outline" :disabled="files.length == 0" @click="bulkRegister()">开始导入</el-button></el-row>
                            <br>
                            <el-row v-if="files.length == 0" style="color: red;">*请添加文件</el-row>
                        </el-card>
                    </el-row>
                    <el-row>
                        <br>
                    </el-row>
                    <el-row type="flex" justify="space-around">
                        <el-button icon="el-icon-download" style="margin: 0 auto;">
                            <el-link type="info">
                                <a href="http://localhost:8000/excel/student_info.xls" download>模板下载</a>
                            </el-link>
                        </el-button>
                    </el-row>
                </el-col>
                <!-- <el-col :span="6">
                    
                </el-col> -->
            </el-row>
        </page-main>
  </div>
</template>

<script>
export default {
    name: 'basicDataImport',
    data() {
        return {
            files: []
        }
    },
    methods: {
        handlesuccess3(res, file) {
            this.files.push({
                name: file.name,
                url: res != '' ? res : ''
            })
            this.$nextTick(() => {
                if (res == '') {
                    this.$message.warning(res.error)
                    this.files.pop()
                }
            })
            console.log(this.files);
        },
        bulkRegister() {
            let that = this
            this.files.forEach(item => {
                let url =  item.url.slice(-17)
                that.$util.post('public/bulkRegister', {filePath: url}).then(res => {
                    that.$message({
                        message: '新增成功',
                        type: 'success'
                    });
                })
            })
        }
    }
}
</script>

